import { fetchList } from ".";
import MarkLevelComponent from "./components/MarkLevel";
import {
  modal_disable_ok_button,
  modalFormState,
  modalInstance,
  modalLoading,
  modalTitle,
  modalVisible,
  operateType,
  tableActiveKey,
} from "./store";
import { drawerVisible } from "@user/popular/drawer";
export const modalConfig = () => {
  const defineModal = {
    modalInstance,
    loading: modalLoading,
    visible: modalVisible,
    maskClosable: true,
    disable_ok_button: modal_disable_ok_button,
    disable_cancel_buttton: false,
    reverse: ref(true),
    title: modalTitle,
    formState: modalFormState,
    on: {
      async finish(values: any) {
        switch (operateType.value) {
          case "agree":
            try {
              modalLoading.value = true;
              const res: any = await authApi.updatePass({
                real_person_id: modalFormState.real_person_id,
              });
              if (res.code != 200) return message.error(res.message);
              message.success($t("base.updateSucess"));
              fetchList();
            } catch (error: any) {
              message.error(error.message);
            } finally {
              modalLoading.value = false;
              modalVisible.value = false;
              drawerVisible.value = false;
            }

            break;

          case "refuse":
            try {
              modalLoading.value = true;
              const res: any = await authApi.updateReject({
                real_person_id: modalFormState.real_person_id,
                reason: modalFormState.reason,
              });
              if (res.code != 200) return message.error(res.message);
              message.success($t("base.updateSucess"));
              fetchList();
            } catch (error: any) {
              message.error(error.message);
            } finally {
              modalLoading.value = false;
              modalVisible.value = false;
              drawerVisible.value = false;
            }
            break;

          case "markLevel":
            try {
              modalLoading.value = true;
              const res: any = await popularApi.update({
                editId: modalFormState.editId,
                level: modalFormState.level,
              });
              if (res.code != 200) return message.error(res.message);
              message.success(res.message);
              fetchList();
            } catch (error: any) {
              message.error(error.message);
            } finally {
              modalLoading.value = false;
              modalVisible.value = false;
            }
            break;
        }
      },
    },
    slot: {
      extra_form_item: () => {
        return (
          <>
            <div class="mb16" style="width:100%">
              {operateType.value === "agree" ? (
                tableActiveKey.value === 0 ? (
                  "同意客人真人认证审核后，客户将获得真人认证徽章等权益。"
                ) : (
                  "同意客户人气认证审核后，客户认证信息将进入人气投票环节，人气等级将根据投票情况获取。"
                )
              ) : operateType.value === "refuse" ? (
                <a-form-item
                  labelCol={{ span: 4 }}
                  wrapperCol={{ span: 20 }}
                  style="width:100%"
                  label="说明"
                  help={
                    <div class="fs11">
                      拒绝原因说明，将以系统消息的形式通知认证发起者
                    </div>
                  }
                >
                  <a-textarea
                    vModel:value={modalFormState.reason}
                    rows={4}
                    show-count
                    maxlength={20}
                    placeholder="请输入拒绝此次真人认证的原因，内容长度限制20字以内"
                  />
                </a-form-item>
              ) : operateType.value === "markLevel" ? (
                <MarkLevelComponent />
              ) : null}
            </div>
          </>
        );
      },
    },
  };
  return defineModal;
};
